var HOST_URL = document.location.origin;
// var HOST_URL = "https://yttrade.bus365.cn";
var YTHOST_URL = HOST_URL;
var TOAST_LENGTH = 3000;
var VERSION = "5.3.0";
if (HOST_URL.indexOf("yttrade.bus365") > -1) { //正式环境
	console.log = function () { }
}
//rem适配
(function (doc, win) {
	var docEl = doc.documentElement,
		resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
		recalc = function () {
			var clientWidth = docEl.clientWidth;
			if (!clientWidth) return;
			docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
		};
	if (!doc.addEventListener) return;
	win.addEventListener(resizeEvt, recalc, false);
	doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
// 查询页面按钮颜色
function queryButtonColor() {
	var dataparam = {};
	fly.get(YTHOST_URL + "/yt/c/v1.0/page/querybuttoncolor", dataparam)
		.then(function (res) {
			res = JSON.parse(res);
			if (res.code == "0000") {
				$(".pageButtonColor").css("background-color", res.data);
				$(".pageTextColor").css("color", res.data);
				$(".pageBorderColor").css("border-color", res.data);
			} else {
				alertTip(res.message, 2000);
			}
		})
		.catch(function (error) {
			console.log(error);
		});
}
Array.prototype.remove = function (dx) {

	if (isNaN(dx) || dx > this.length) {
		return false;
	}
	for (var i = 0, n = 0; i < this.length; i++) {
		if (this[i] != this[dx]) {
			this[n++] = this[i]
		}
	}
	this.length -= 1
}
Array.prototype.removeAt = function (index) {
	if (isNaN(index) || index >= this.length) {
		return false;
	}
	this.splice(index, 1);
}
Array.prototype.contain = function (obj) {
	return this.indexOf(obj) !== -1;
}
String.prototype.format = function () {
	var regexp = /\{(\d+)\}/g;
	var args = arguments;
	var result = this.replace(regexp, function (m, i, o, n) {
		return args[i];
	});
	return result.replaceAll('%', String.EscapeChar);
}

/// <summary>
/// 替换所有字符串
/// </summary>
/// <param name="searchValue">检索值</param> 
/// <param name="replaceValue">替换值</param> 
String.prototype.replaceAll = function (searchValue, replaceValue) {
	var regExp = new RegExp(searchValue, "g");
	return this.replace(regExp, replaceValue);
}

function replaceNull(value) {
	if (value != null && value != "") {
		value.replace(" ", "");
	}
	return value;
}
//url传值方法
//解析URL
function parseURL(url) {
	var a = document.createElement('a');
	a.href = url;
	return {
		source: url,
		protocol: a.protocol.replace(':', ''),
		host: a.hostname,
		port: a.port || '80',
		query: a.search,
		params: (function () {
			var ret = {},
				seg = a.search.replace(/^\?/, '').split('&'),
				len = seg.length,
				i = 0,
				s;
			for (; i < len; i++) {
				if (!seg[i]) {
					continue;
				}
				s = seg[i].split('=');
				ret[s[0]] = s[1];
			}
			return ret;
		})(),
		file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
		hash: a.hash.replace('#', ''),
		path: a.pathname.replace(/^([^\/])/, '/$1'),
		relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
		segments: a.pathname.replace(/^\//, '').split('/')
	};
}
//url传值方法
function getQueryString(href, name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = href.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null;
}

function getParamString(paramstr, key) {
	var paramarray = paramstr.split("_");
	var retstr = null;
	for (var i = 0; i < paramarray.length; i++) {
		var getkey = paramarray[i].split("*")[0];
		if (getkey == key) {
			retstr = paramarray[i].split("*")[1];
			break;
		}

	}
	return retstr;
}
//当前日期
var myDate = new Date();
var Year = myDate.getFullYear();
var Month = myDate.getMonth() + 1;
Month = Month >= 10 ? Month : "0" + Month;
var Hour = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();
var Minute = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
var Day = myDate.getDate();
Day = Day >= 10 ? Day : "0" + Day;
var day = myDate.getDate();
var today = Year + "-" + Month + "-" + addZero(day);
var getDay = myDate.getDay();
var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
var weekDays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
//农历日期
function GetLunarDay(solarYear, solarMonth, solarDay) {
	if (solarYear < 1921 || solarYear > 2020) {
		return "";
	} else {
		solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11;
		e2c(solarYear, solarMonth, solarDay);
		return GetcDateString();
	}
}

function e2c() {
	TheDate = (arguments.length != 3) ? new Date() : new Date(arguments[0], arguments[1], arguments[2]);
	var total, m, n, k;
	var isEnd = false;
	var tmp = TheDate.getYear();
	if (tmp < 1900) {
		tmp += 1900;
	}
	total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + madd[TheDate.getMonth()] + TheDate.getDate() - 38;
	if (TheDate.getYear() % 4 == 0 && TheDate.getMonth() > 1) {
		total++;
	}
	for (m = 0; ; m++) {
		k = (CalendarData[m] < 0xfff) ? 11 : 12;
		for (n = k; n >= 0; n--) {
			if (total <= 29 + GetBit(CalendarData[m], n)) {
				isEnd = true;
				break;
			}
			total = total - 29 - GetBit(CalendarData[m], n);
		}
		if (isEnd) break;
	}
	cYear = 1921 + m;
	cMonth = k - n + 1;
	cDay = total;
	if (k == 12) {
		if (cMonth == Math.floor(CalendarData[m] / 0x10000) + 1) {
			cMonth = 1 - cMonth;
		}
		if (cMonth > Math.floor(CalendarData[m] / 0x10000) + 1) {
			cMonth--;
		}
	}
}

function GetcDateString() {
	var tmp = "";
	if (cMonth < 1) {
		tmp += monString.charAt(-cMonth - 1);
	} else {
		tmp += monString.charAt(cMonth - 1);
	}
	tmp += "月";
	tmp += (cDay < 11) ? "初" : ((cDay < 20) ? "十" : ((cDay < 30) ? "二十" : "三十"));
	if (cDay % 10 != 0 || cDay == 10) {
		tmp += numString.charAt((cDay - 1) % 10);
	}
	return tmp;
}
var CalendarData = new Array(100);
var madd = new Array(12);
var tgString = "甲乙丙丁戊己庚辛壬癸";
var dzString = "子丑寅卯辰巳午未申酉戌亥";
var numString = "一二三四五六七八九十";
var monString = "正二三四五六七八九十冬腊";
var weekString = "日一二三四五六";
var sx = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
var cYear, cMonth, cDay, TheDate;
CalendarData = new Array(0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5,
	0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B,
	0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6,
	0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54,
	0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B,
	0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D,
	0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95);
madd[0] = 0;
madd[1] = 31;
madd[2] = 59;
madd[3] = 90;
madd[4] = 120;
madd[5] = 151;
madd[6] = 181;
madd[7] = 212;
madd[8] = 243;
madd[9] = 273;
madd[10] = 304;
madd[11] = 334

function GetBit(m, n) {
	return (m >> n) & 1;
}
/*
 *将当前日期置为后一天
 */
function addDate(date, days) {
	var d = new Date(date);
	d.setDate(d.getDate() + days);
	return d
}
/*
 *将当前日期置为前一天
 */
function reduceDate(date, days) {
	var d = new Date(date);
	d.setDate(d.getDate() - days);
	return d
}
/*
 *将毫秒数转为 YY-MM-DD
 */
function formatDate(val) {
	if (!val) return
	var today = new Date(val);
	today = today.getFullYear() + "-" + ((today.getMonth() + 1) < 10 ? "0" + (today.getMonth() + 1) : today.getMonth() + 1) +
		"-" + (today.getDate() < 10 ? "0" + today.getDate() : today.getDate());
	return today
}

function DateDiff(sDate1, sDate2) {
	var aDate, oDate1, oDate2, iDays;
	aDate = sDate1.split("-");
	oDate1 = new Date(aDate[0], aDate[1] - 1, aDate[2]);
	aDate = sDate2.split("-");
	oDate2 = new Date(aDate[0], aDate[1] - 1, aDate[2]);
	iDays = parseInt((oDate1 - oDate2) / 1000 / 60 / 60 / 24);
	return iDays
}

function getDateByString(str) {
	var d = new Date(str.replace(/-/g, "/"));
	return d;
}
//公共弹出框
function alertTip(word, tick, fn) {
	var conStr = '<div id="conDiv" class="alertTip">' + word + "</div>";
	$("body").append(conStr);
	setTimeout(function () {
		$("#conDiv").remove();
		if (fn != null) {
			fn();
		}
	}, tick);
}
//公共提示框
function alertWhiteDialog(word, fn) {
	var conStr = '<div class="alertback"><div class="alertmain"><div class="alert_title">温馨提示</div>'
	conStr += '<div id="contentid" class="content">' + word + '</div><div class="contentline"></div>';
	conStr +=
		'<div id="cancelid" class="alert_cancel">返回</div><div id="confirmid" class="alert_confirm">确定</div></div></div>';
	$("body").append(conStr);
	$("#confirmid").click(function () {
		$(".alertback").remove();
		if (fn != null) {
			fn();
		}
	});
	$("#cancelid").click(function () {
		$(".alertback").remove();
	});
}
//公共提示框
function alertSureDialog(word, title, btntext) {
	if (title) {
		var conStr = '<div class="alertback"><div class="alertmain"><div class="alert_title">' + title + '</div>'
	} else {
		var conStr = '<div class="alertback"><div class="alertmain"><div class="alert_title">温馨提示</div>'
	}
	conStr += '<div id="contentid" class="content">' + word + '</div><div class="contentline"></div>';
	if (btntext) {
		conStr += '<div id="cancelid" class="alert_sure">' + btntext + '</div></div></div>';
	} else {
		conStr += '<div id="cancelid" class="alert_sure">确定</div></div></div>';
	}
	$("body").append(conStr);
	$(".alertback").click(function () {
		$(this).remove();
	});
	$("#cancelid").click(function () {
		$(".alertback").remove();
	});
}
//公共提示框
function alertWhiteDialogFn(id, word, lefttitle, righttitle, leftFn, rightFn, title) {
	if (title) {
		var conStr = '<div class="alertback"><div class="alertmain"><div class="alert_title">' + title + '</div>'
	} else {
		var conStr = '<div class="alertback"><div class="alertmain"><div class="alert_title">温馨提示</div>'
	}
	conStr += '<div id="contentid" class="content">' + word + '</div><div class="contentline"></div>';
	conStr += '<div id="cancelid" class="alert_cancel">' + lefttitle + '</div><div id="confirmid" class="alert_confirm">' +
		righttitle + '</div></div></div>';
	$("body").append(conStr);
	$("#confirmid").click(function () {
		$(".alertback").remove();
		if (rightFn != null) {
			rightFn(id);
		}
	});
	$("#cancelid").click(function () {
		$(".alertback").remove();
		if (leftFn != null) {
			leftFn(id);
		}

	});
}
var loadObj = {
	loading: function (loadtext) {
		var path = window.location.pathname;
		var arr = path.split("/");
		var imgPath = "images/loading.gif";
		if (arr != null && arr.length > 0) {
			for (var i = 0; i < arr.length - 4; i++) {
				imgPath = "../" + imgPath;
			}
		}
		var html = '';
		html += '<div class=bg-box onclick="javascript:void(0)">';
		if (!loadtext) {
			html += '<div class="fading-circle">';
			html += '<img src="' + imgPath + '" class=loadImg>';
			html += '</div>';
		} else {
			html += '<div class="fading-circle-text">';
			html += '<img src="' + imgPath + '" class="loadImg-text">';
			html += '<div class="loading-text">' + loadtext + '</div>';
			html += '</div>';
		}
		html += '</div>';
		$("body").append(html);
	},
	stopLoading: function () {
		$(".bg-box").remove();
	}
}
var checker = {
	isName: function (str) {
		if (str == "") {
			return window.errMes.nullName;
		}
		//str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
		var regexp = /^[\u4e00-\u9fa5]{2,15}$/;
		var re = /^[a-zA-Z\/ ]{4,30}$/;
		var b1 = regexp.test(str);
		var b2 = re.test(str);
		if (!b1 && !b2) {

			return "中文姓名2~15个汉字或英文姓名4~30个英文";

		}
		return "";
	},
	isPhone: function (str) {
		if (str == "") {
			return window.errMes.nullphone;

		} else {
			str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
			var isPhoneReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
			var rs = checker.check(isPhoneReg, str, 1);
			if (!rs) {
				return errMes.realPhone;
			}
		}
		return "";
	},
	isChineseCharacter: function (str) {
		if (str == "") {
			return window.errMes.nullphone;

		} else {
			var ischineseReg = /^[\u4E00-\u9FA5]+$/;
			var rs = checker.check(ischineseReg, str, 1);
			if (!rs) {
				return errMes.realPhone;
			}
		}
		return "";
	},
	isPassword: function (str) {
		if (str) {
			var regexp = /^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,20}$/;
			return regexp.test(str)
		} else {
			return false
		}
	},
	isNull: function (str) {
		if (str) {
			return true
		} else {
			return false
		}
	},
	isEmail: function (str) {
		if (str == "") {
			alertTip(window.errMes.nullemail, TOAST_LENGTH);
			return false;

		} else {
			var isEmailReg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
			return checker.check(isEmailReg, str, 2)
		}
	},
	isEmail_notip: function (str) {
		if (str == "") {
			alertTip(window.errMes.nullemail, TOAST_LENGTH);
			return false;

		} else {
			var isEmailReg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
			return checker.check_notip(isEmailReg, str, 2)
		}
	},
	isPhone: function (str) {
		if (str == "") {
			alertTip(window.errMes.nullphone, TOAST_LENGTH);
			return false
		} else {
			str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
			var isPhoneReg = /^1[3|7|4|5|8|9|6][0-9]{9}$/;
			return checker.check(isPhoneReg, str, 1)
		}
	},
	isPhone_notip: function (str) {
		if (str == "") {
			alertTip(window.errMes.nullphone, TOAST_LENGTH);
			return false
		} else {
			str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
			var isPhoneReg = /^1[3|7|4|5|8|6|9][0-9]{9}$/;
			return checker.check_notip(isPhoneReg, str, 1)
		}
	},

	isUserName: function (str) {
		if (!str) {
			alertTip(window.errMes.username, TOAST_LENGTH);
			return false
		} else {
			if (str.indexOf("@") > 0) {
				return checker.isEmail(str)
			} else {
				return checker.isPhone(str)
			}
		}
	},
	check: function (reg, str, type) {
		if (reg && reg.test(str)) {
			return reg.test(str)
		} else {
			if (type == 1) {
				alertTip(window.errMes.phone, TOAST_LENGTH)
			} else {
				if (type == 2) {
					alertTip(window.errMes.email, TOAST_LENGTH)
				}
			}
			return false
		}
	},
	check_notip: function (reg, str, type) {
		if (reg && reg.test(str)) {
			return reg.test(str)
		} else {
			if (type == 1) {

			} else {
				if (type == 2) {

				}
			}
			return false
		}
	},
	checkNotip: function (reg, str, type) {
		if (reg && reg.test(str)) {
			return reg.test(str)
		} else {
			if (type == 1) {

			} else {
				if (type == 2) {

				}
			}
			return false
		}
	},
	isRealName: function (str) {
		if (str == "") {
			alertTip(window.errMes.nullrealname, TOAST_LENGTH);
			return false
		}
		str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
		var regexp = /[\u4e00-\u9fa5]/g;
		var re = /^\S+[a-z A-Z]$/;
		if (regexp.test(str)) {
			if (str.length < 15 && str.length >= 2) {
				return (str.length < 15 && str.length >= 2)
			} else {
				alertTip("中文姓名2~15个汉字", TOAST_LENGTH);
				return false
			}
		} else {
			if (re.test(str)) {
				if (str.length < 30 && str.length > 3) {
					return (str.length < 30 && str.length > 3)
				} else {
					alertTip("英文姓名4~30个英文", TOAST_LENGTH);
					return false
				}
			} else {
				alertTip(window.errMes.realname, TOAST_LENGTH);
				return false
			}
		}
	},
	isIdCardRealName: function (str) { //真实身份证姓名验证（包含中文.·）
		if (str == "") {
			alertTip(window.errMes.nullidcardrealname, TOAST_LENGTH);
			return false
		}
		str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
		var regexp = /^[\u4e00-\u9fa5][\u4e00-\u9fa5·.]*[\u4e00-\u9fa5]$/g;
		if (regexp.test(str)) {
			if (str.length <= 20 && str.length >= 2) {
				return (str.length <= 20 && str.length >= 2)
			} else {
				alertTip("中文姓名2~20个汉字", TOAST_LENGTH);
				return false
			}
		} else {
			return false
		}
	},
	isCardCode: function (str) {
		if (!str) {
			alertTip(errMes["nullCardCode"])
		} else {
			var num = str.toUpperCase();
			if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
				alertTip(errMes["cardCode"]);
				return false
			}
			var len, re;
			len = num.length;
			if (len == 15) {
				re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
				var arrSplit = num.match(re);
				var dtmBirth = new Date("19" + arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
				var bGoodDay;
				bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (
					dtmBirth.getDate() == Number(arrSplit[4]));
				if (!bGoodDay) {
					alertTip(errMes["cardCode"]);
					return false
				} else {
					if (new Date().getYear() < dtmBirth.getYear()) {
						return false
					} else {
						var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
						var arrCh = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
						var nTemp = 0,
							i;
						num = num.substr(0, 6) + "19" + num.substr(6, num.length - 6);
						for (i = 0; i < 17; i++) {
							nTemp += num.substr(i, 1) * arrInt[i]
						}
						num += arrCh[nTemp % 11];
						return true
					}
				}
			}
			if (len == 18) {
				re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
				var arrSplit = num.match(re);
				var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
				var bGoodDay;
				bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) &&
					(dtmBirth.getDate() == Number(arrSplit[4]));
				if (!bGoodDay) {
					alertTip(errMes["cardCode"]);
					return false
				} else {
					var valnum;
					var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
					var arrCh = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
					var nTemp = 0,
						i;
					for (i = 0; i < 17; i++) {
						nTemp += num.substr(i, 1) * arrInt[i]
					}
					valnum = arrCh[nTemp % 11];
					return true
				}
			}
			alertTip(errMes["cardCode"]);
			return false
		}
	},
	isNickname: function (str) {
		if (str) {
			if (str.replace(/^\s\s*/, "").replace(/\s\s*$/, "").length <= 5) {
				return true
			} else {
				return false
			}
		} else {
			return false
		}
	},
	checkisnull: function (str) {
		if (str == null || str == "null" || str == "" || str == undefined || str == "NaN" || str == "(null)" || str ==
			"undefined") {
			return true;
		} else {
			return false;
		}
	}
}

window.errMes = {
	phone: "请输入正确的手机号！",
	nullphone: "请输入手机号! ",
	username: "请输入正确的用户名！",
	pwd: "请输入正确的密码！",
	newPWD: "请输入正确的新密码！",
	Cpwd: "两次输入的密码不一致！",
	nickname: "请输入正确的昵称！",
	realname: "请输入正确的姓名！",
	nullrealname: "请输入姓名! ",
	noActive: "对不起，您的账号没有激活，请激活后使用！",
	email: "请输入正确的邮箱! ",
	nullemail: "请输入邮箱! ",
	active_user_email: "手机购票系统不能做邮箱会员激活，请到网站激活后手机购票系统才可以正常使用！",
	network_err: "网络异常，请稍后尝试！",
	cardCode: "请输入正确的身份证号码",
	nullCardCode: "请输入身份证号码",
	orderno: "请输入正确的订单号！",
	nullName: "请输入正确姓名",
	realPhone: "请输入正确的手机号码",
	realcarid: "请输入正确的身份证号码"
}
//星期转化
function getDays(y, m, d) {
	m = parseInt(m);
	m = m - 1;
	m = "0" + m;
	var date;
	if (y) {
		date = new Date(y, m, d)
	} else {
		date = new Date()
	}
	var weekDay = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	return weekDay[date.getDay()]
}
//保留两位小数
function changeTwoDecimal(x) {
	var f_x = parseFloat(x);
	if (isNaN(f_x)) {
		return false
	}
	var f_x = Math.round(x * 100) / 100;
	var newSx = String(f_x);
	if (newSx.indexOf(".") == -1) {
		newSx += ".00"
	} else {
		if (newSx.split(".")[1].length == 1) {
			newSx += "0"
		}
	}
	return newSx
}
//日期格式
Date.prototype.format = function (format) {
	var o = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S": this.getMilliseconds()
	};
	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length))
		}
	}
	return format
};
//计时
var timeFn;
var fn;

function countDown(staticTime, allTime, fu, lastFu) {
	if (timeFn) {
		clearInterval(timeFn);
		if (fn && typeof (fn) == "function") {
			fn(0)
		}
		timeFn = null;
		fn = null
	}
	fn = lastFu;
	timeFn = setInterval(function () {
		var nowTime = new Date().getTime();
		var surplusTime = allTime - Math.floor((nowTime - staticTime) / 1000);
		if (surplusTime > 0) {
			fu(surplusTime)
		} else {
			clearInterval(timeFn);
			lastFu(0);
			timeFn = null;
			fn = null
		}
	}, 1000);
	return function () {
		clearInterval(timeFn);
		timeFn = null;
		fn = null
	}
}

function clearCountDow() {
	if (timeFn) {
		clearInterval(timeFn);
		timeFn = null;
		fn = null
	}
}
//小数点
function changeTwoDecimal(x) {
	var f_x = parseFloat(x);
	if (isNaN(f_x)) {
		return false
	}
	var f_x = Math.round(x * 100) / 100;
	var newSx = String(f_x);
	if (newSx.indexOf(".") == -1) {
		newSx += ".00"
	} else {
		if (newSx.split(".")[1].length == 1) {
			newSx += "0"
		}
	}
	return newSx
}

function isLogininfoNULL(vipinfo) {
	vipinfo = vipinfo + "";
	if (vipinfo == "" || vipinfo == "null" || vipinfo == "undefined") {
		return ""
	} else {
		return vipinfo
	}
}

//日期不足两位补0
function addZero(datastr) {
	var datastrnow = datastr;
	if (datastrnow < 10) {
		datastrnow = "0" + datastrnow;
	}
	return datastrnow;
}
/*
 * 判断是否微信
 */
function isWeiXin() {
	var ua = window.navigator.userAgent.toLowerCase();
	if (ua.match(/MicroMessenger/i) == 'micromessenger') {
		return true;
	} else {
		return false;
	}
}
//字符串转时间 param格式 yyyy-mm-dd
function retDate(param) {
	var splitarr = param.split("-");
	param = "";
	for (var i = 0; i < (splitarr.length); i++) {
		param += splitarr[i]
		if (i < (splitarr.length - 1)) {
			param += "/";
		}
	}
	var dateret = new Date(param);
	return dateret;
}
/*
 * 判断当前val是否为空
 */
function isNull(val) {
	if (val == null || val == "null" || val == "" || val == undefined || val == "undefined") {
		return null;
	} else {
		return val;
	}
}
//验证身份证号并获取出生日期
function getBirthdatByIdNo(iIdNo) {
	var tmpStr = "";
	var idDate = "";
	var tmpInt = 0;
	var strReturn = "";

	if ((iIdNo.length != 15) && (iIdNo.length != 18)) {
		strReturn = "输入的身份证号位数错误";
		return strReturn;
	}

	if (iIdNo.length == 15) {
		tmpStr = iIdNo.substring(6, 12);
		tmpStr = "19" + tmpStr;
		tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)

		return tmpStr;
	} else {
		tmpStr = iIdNo.substring(6, 14);
		tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)

		return tmpStr;
	}
}
//获取性别
function getSexByIdNo(idNo) {
	var sex;
	if (idNo.length == 18) {
		if (parseInt(idNo.substr(16, 1)) % 2 == 1) {
			sex = "男";
		} else {
			sex = "女";
		}
	}

	if (idNo.length == 15) {
		if (parseInt(idNo.substr(14, 1)) % 2 == 1) {
			sex = "男";
		} else {
			sex = "女";
		}
	}
	return sex;
}
/**
 * 动态加载script
 */
function appendScript(src) {
	var index = src.indexOf('//');
	if (index === -1) {
		return;
	}
	src = src.substring(index);
	src = window.location.protocol + src;
	var head = document.getElementsByTagName('head')[0];
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = src;
	head.appendChild(script);

}

/**
 * 获取拼接参数
 */
function getContactParamsString(paramMap) {
	var str = "";
	for (var key in paramMap) {
		str = str + key + "=" + paramMap[key] + "&";
	}
	return str;
}

function Base64() {

	// private property
	var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

	// public method for encoding
	this.encode = function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = _utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
				_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
				_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
		}
		return output;
	}

	// public method for decoding
	this.decode = function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = _keyStr.indexOf(input.charAt(i++));
			enc2 = _keyStr.indexOf(input.charAt(i++));
			enc3 = _keyStr.indexOf(input.charAt(i++));
			enc4 = _keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = _utf8_decode(output);
		return output;
	}
	// private method for UTF-8 encoding
	_utf8_encode = function (string) {
		string = string.replace(/\r\n/g, "\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if ((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}
		return utftext;
	}

	// private method for UTF-8 decoding
	_utf8_decode = function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while (i < utftext.length) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i + 1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i + 1);
				c3 = utftext.charCodeAt(i + 2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
/*
 * 判断用户是否登录
 */
function userisLogin() {
	if (isNull(localStorage.clienttoken) && isNull(localStorage.phonenum)) {
		return true;
	} else {
		return false;
	}
}
/*自定义input清楚按钮*/
function btnclearup(callback) {
	$.each($('input'), function (i, o) {
		if ($(o).attr('data-clearup') && $(o).attr('data-clearup') == 'true') {
			var width = $(o).width(); //当前input框宽度
			var height = $(o).height(); //当前input框高度
			var left = $(o).offset().left; //当前input框距离左边的距离
			var top = $(o).offset().top; //当前input框距离顶部的距离
			var icon_clearup =
				'<img class="btn_clearup" style="width:0.36rem;margin:0;padding:0;position:absolute;z-index:999;left:' + (left +
					width - 30) + 'px;top:' + (top + 5) + 'px;" src="' + HOST_URL + '/public/www/images/icon_clearup.png">';
			if ($(o).parents('.tit').length > 0 || $(o).attr('data-position') == 'fixed') {
				icon_clearup =
					'<img class="btn_clearup" style="width:0.36rem;margin:0;padding:0;position:fixed;z-index:999;left:' + (left +
						width - 30) + 'px;top:' + (top + 5) + 'px;" src="' + HOST_URL + '/public/www/images/icon_clearup.png">';
			}
			$(o).bind('input', function () {
				if ($('.btn_clearup').length > 0) {

				} else {
					$('body').append(icon_clearup);
				}

				$('.btn_clearup').click(function () {
					$('.btn_clearup').remove();
					$(o).val('');
					if (callback) {
						callback();
					}
				});
				if ($(o).val() == '') {
					$('.btn_clearup').remove();
				}
			})

		}
	})
}
/*
 * 初始化底部导航
 */
function initBottomNav() {
	var curid = $('.nav_item_active').attr('id');
	$('.nav_wrap .nav_item').click(function () {
		var eleid = $(this).attr('id');
		if (curid == eleid) return;
		switch (eleid) {
			case 'homepage':
				if (isNull(localStorage.homepageurl)) {
					window.location.href = localStorage.homepageurl;
				}
				break;
			case 'trip':
				if (curid == 'homepage') {
					localStorage.homepageurl = window.location.href;
				}
				window.location.href = YTHOST_URL + '/public/www/trip.html';
				break;
			case 'user':
				if (curid == 'homepage') {
					localStorage.homepageurl = window.location.href;
				}
				window.location.href = YTHOST_URL + '/public/www/home-page-user.html';
				break;
		}
	})
}
/**
 * 修复精度
 */
function toFixed(num, s) {
	var times = Math.pow(10, s)
	var des = num * times + 0.5
	des = parseInt(des, 10) / times
	return des + ''
}
/**
 * 修改指定地址参数
 */
function changeUrlParam(url, paramkey, paramval) {
	var url = decodeURIComponent(url);
	var pattern = paramkey + '=([^&]*)';
	var replaceText = paramkey + '=' + paramval;
	if (url.match(pattern)) {
		var tmp = '/(' + paramkey + '=)([^&]*)/gi';
		tmp = url.replace(eval(tmp), replaceText);
		return tmp;
	} else {
		if (url.match('[\?]')) {
			return url + '&' + replaceText;
		} else {
			return url + '?' + replaceText;
		}
	}
	return url + '\n' + paramkey + '\n' + paramval;
}
